<template>
  <div>
    <vol-box
      :lazy="true"
      v-model="testModel"
      title="选择采购申请单"
      :height="400"
      :width="1200"
      :padding="5"
    >
      <purchaseApplication ref="purchaseApplication"></purchaseApplication>
      <el-button type="primary" @click="confirmBtnFn">Primary</el-button>
    </vol-box>
  </div>
</template>

<script>
import VolBox from "@/components/basic/VolBox.vue";
import purchaseApplication from "@/views/purchaseinfo/purchase_application/q_purchase_application.vue";
export default {
  components: {
    "vol-box": VolBox,
    purchaseApplication,
  },
  props:{
    testModel:{
      type:Boolean,
      default:false
    }
  },
  data() {
    return {
      purchaseApplicationModel: false,
     
    };
  },
  methods: {
    confirmBtnFn() {
      conosle.log("rowObj");
    },
    detailPurchaseApplicationOpen() {
      this.purchaseApplicationModel = true;
    },
    purchaseApplicationOnSelect() {
      let rowObj = this.$refs.purchaseApplication.$refs.grid.getSelectRows();
      console.log("rowObj", rowObj);
      if (rowObj.length) {
        this.$emit("parentCall", ($parent) => {
          let detailRowData = $parent.$refs.detail.rowData;
          let num = 0;
          detailRowData.forEach((item) => {
            rowObj.forEach((o) => {
              if (o.Voucher_sub == item.Voucher_sub) num++;
            });
          });

          if (!num) {
            let newRowObj = rowObj.map((item) => {
              return {
                Voucher_sub: item.Voucher_sub,
              };
            });
            this.$emit("parentCall", ($parent) => {
              $parent.$refs.detail.rowData.unshift(...newRowObj);
            });
            return (this.purchaseApplicationModel = false);
          } else {
            this.$message.error("此采购单已包含该申请单");
          }
        });
      } else {
        return this.$message.error("请选择采购申请单");
      }
    },
  },
};
</script>

<style scoped>
.box {
  max-height: 500px;
  overflow: auto;
}
.topBox {
  padding: 20px 0;
  border-bottom: 1px solid #eaeaea;
}
.el-icon-search {
  display: inline-block;
}
.topBox,
.demo-input-suffix {
  display: flex;
  line-height: 31px;
}
.demo-input-suffix {
  width: 40%;
  margin-left: 10px;
}
label {
  width: 160px;
  text-align: right;
}
.el-select {
  width: 65%;
}
.qureyBtn {
  margin-left: 30px;
  padding: 0 30px;
}
.bottomBox {
  padding: 40px 5px;
  max-height: 377px;
  overflow: auto;
}
.footBox {
  float: right;
  padding: 10px 20px;
}
.confirmBtn {
  padding: 0 20px;
}
</style>